<script type="text/javascript" >
    stFacebookToolbox.load_tooltip();
    stFacebookToolboxcustom.on_submitform_new('#stFacebookToolboxForm');
    stFacebookToolbox.loadUploadButton('50');
    stFacebookToolbox.loadRemoveButton();
     jQuery(document).ready(function(){
         <?php if($action == 'add_coupon_template'){?>
                 jQuery('#coupon').show();
                    jQuery('#site_map').hide();
                    jQuery('#gallery_app').hide();
                    jQuery('#inner_content').css('width','87%');
                        jQuery('#inner_content').css('float','right');
                        jQuery('#side-nav').fadeIn('normal');
                        jQuery("#tabs ul li").each(function(){
                        if(jQuery(this).children().attr('action') == 'gallery_app' || jQuery(this).children().attr('action') == 'coupon')
                            jQuery(this).hide();
                        if(jQuery(this).children().attr('action') == 'home_applications')
                            jQuery(this).attr('class','current');
                        });
                        jQuery("a[action='coupon_template']").parent().attr('class','current');
                 <?php }?>
        jQuery('#from').datetimepicker({"dateFormat":"dd.mm.yy"});
        jQuery('#to').datetimepicker({"dateFormat":"dd.mm.yy"});
       jQuery("a.add-new-h2").click(function(){
           jQuery("#coupon_name").val(jQuery("#name").val());
           jQuery("#coupon_title").val(jQuery("#title").val());
           jQuery("#coupon_text").val(jQuery("#description").val());
           jQuery("#coupon_second").val(jQuery("#second").val());
           jQuery("#coupon_template").val(jQuery("#graphic").val());
//           if(jQuery("#to").val() != ''){
//               var string = jQuery("#from").val()
//               jQuery("#date") = string.split(' ')[0];
//           }
           document.pdf.submit(); 
        });
     });
     function graphic(id){
         var array = new Array();
         <?php 
         foreach($graphic as $row){
             echo "array[{$row->CouponTemplateGraphicsID}] = '{$row->TemplatesGraphicsPath}';";
         }
         ?>
         jQuery("#graphic_image").attr('src','https://s3-ap-southeast-1.amazonaws.com/<?php echo $config['gallery_bucket'];?>/<?php echo 'fb-app-coupon/';?>'+array[id]);
     }
     jQuery("#graphic").change(function(){
        graphic(jQuery("#graphic").val());
     });
     graphic(jQuery("#graphic").val());
     function make_pdf(){
         
     }
     function check_type(check){
         if(check == 2){
             jQuery("#type_hide").slideUp();
             jQuery("#title").val('null');
             jQuery("#description").val('null');
             jQuery("#url_display").slideDown();
         }
         else {
             jQuery("#type_hide").slideDown();
             jQuery("#url_display").slideUp();
         }
     }
     function func_auto_post(check){
         if(check){
             jQuery("#display_autopost").slideDown();
         }
         else {
             jQuery("#display_autopost").slideUp();
         }
     }
</script>
<style>
    #stcontainer .w100p table td {
    border-bottom: 1px solid #FFFFFF;
    padding: 0;
}
#stcontainer .w100p table {
    table-layout: fixed;
    width: auto;
}
</style>
<form name="pdf" action="<?php echo get_bloginfo('url');?>/coupon/preview.php" method="POST" target="_blank">
    <input type="hidden" name="coupon_name" id="coupon_name" />
    <input type="hidden" name="coupon_title" id="coupon_title" />
    <input type="hidden" name="coupon_text" id="coupon_text" />
    <input type="hidden" name="coupon_second" id="coupon_second" />
    <input type="hidden" name="coupon_template" id="coupon_template" />
    <input type="hidden" name="date" id="date" value="" />
</form>
<div class="w100p bgl">
    <div class="w100p bgr p5b">
        <form class="stform" id="stFacebookToolboxForm" action="<?php echo admin_url('/admin.php?page=' . $config['plugin_name'] . '&action=' . $current_action) ?>" method="post" >
            <ul>
                <li>
                    <label><?php _e('Campaign Name', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="" class="required" name="data[name]" id="name" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Maximum number of coupons', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="" class="required" name="data[coupon_limit]" id="coupon_limit" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                     <label><?php _e('Campaign type', $config['plugin_name']); ?>:</label>
                    <div class="required">
                       <select name="data[campaign_type]" id="campaign_type" onchange="check_type(this.value)">
                           <option value="1">Coupon campaign</option>
                           <option value="2">External URL campaign</option>
                        </select>
                       
                    </div>
                    <br clear="both" />
                    
                </li>
                <li id="url_display" style="display:none;">
                    <label><?php _e('External URL', $config['plugin_name']); ?>:</label>
                    <div class="">
                        <input value="" class="" name="data[url]" id="url" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <div id="type_hide">
                <li>
                    <label><?php _e('Coupon Title', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="" class="required" name="data[title]" id="title" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Coupon Text', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <textarea name="data[description]" id="description"  class="required"></textarea>
                       
                    </div>
                    <br clear="both" />
                </li>
                 <li>
                    <label><?php _e('Secondary text', $config['plugin_name']); ?>:</label>
                    <div class="">
                        <textarea name="data[second]" id="second"></textarea>
                       
                    </div>
                    <br clear="both" />
                </li>
                 <li>
                    <label><?php _e('Template Graphic', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <select name="data[graphic]" id="graphic" onchange="">
                            <?php 
                            foreach($graphic as $row){
                                echo "<option value='{$row->CouponTemplateGraphicsID}'>{$row->TemplatesGraphicsName}</option>";
                            }
                            ?>
                        </select>
                        <p></p>
                        <img id="graphic_image" width="110" style="margin-left:3px;"/>
                       
                    </div>
                    <br clear="both" />
                </li>
                </div>
                <li>
                    <label><?php _e('User must be page fan to generate coupon', $config['plugin_name']); ?>:</label>
                    <div class="">
                        <input value="1" class="" name="data[is_fan]" id="is_fan" type="checkbox"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Allow user to share campaign', $config['plugin_name']); ?>:</label>
                    <div class="">
                        <input value="1" class="" name="data[is_share]" id="is_share" type="checkbox"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Auto post to users wall', $config['plugin_name']); ?>:</label>
                    <div class="">
                        <input value="1" class="" name="data[auto_post]" id="auto_post" type="checkbox" onclick="func_auto_post(this.checked);"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <div id="display_autopost" style="display:none;">
                <li>
                    <label><?php _e('Wall title', $config['plugin_name']); ?>:</label>
                    <div class="">
                        <input value="" class="" name="data[wall_title]" id="wall_title" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Wall text', $config['plugin_name']); ?>:</label>
                    <div class="">
                        <input value="" class="" name="data[wall_text]" id="wall_text" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Wall image', $config['plugin_name']); ?>:</label>
                    <div class="">
                          <?php
                        $class_hide = "hide";
                        
                        ?>
                                <input type="hidden" id="id_upload_file" name="data[upload_file]" class="" value="">
                                <div class="upload_button_div">
                                    <span class="button image_upload_button" id="upload_file">Upload Image</span>
                                    <span class="button image_reset_button <?php echo $class_hide ?>" id="reset_upload_file" pictureid="upload_file">Remove</span>
                                </div>  
                                
                       
                    </div>
                    <br clear="both" />
                </li>
                </div>
                <li>
                    <label><?php _e('Button image', $config['plugin_name']); ?>:</label>
                    <div class="">
                          <?php
                        $class_hide = "hide";
                        
                        ?>
                                <input type="hidden" id="id_upload_button" name="data[upload_button]" class="" value="">
                                <div class="upload_button_div">
                                    <span class="button image_upload_button" id="upload_button">Upload Button</span>
                                    <span class="button image_reset_button <?php echo $class_hide ?>" id="reset_upload_button" pictureid="upload_button">Remove</span>
                                </div>  
                                
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Discount Type', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <select name="data[type]" id="type">
                            <?php 
                            foreach($type as $row){
                                echo "<option value='{$row->DiscountTypeID}'>{$row->DiscountTypeName}</option>";
                            }
                            ?>
                        </select>
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Discount Value', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="" class="required" name="data[value]" id="value" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Valid From', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="" class="required" name="data[from]" id="from" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                <li>
                    <label><?php _e('Valid To', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="" class="required" name="data[to]" id="to" type="text"  />
                       
                    </div>
                    <br clear="both" />
                </li>
                 <li>
                    <label><?php _e('Coupon detail', $config['plugin_name']); ?>:</label>
                    <div class="">
                        
<!--                       <input type="button" value="Display editor" />-->
                        
                        
                    </div>
                    <br clear="both" />
                </li>
                 <?php
                        echo $option['editor_content'];
                        $functions->customEditor($option['editor_content'],'editor_content');
                        ?>
                
               <li>
                    <input type="submit" id="submitTinyMCE" value="Save"/>
                </li>

          
            </ul>
           
        </form>
    </div>
</div>
